/**
 * Created with IntelliJ IDEA.
 * User: liulinhui
 * Date: 18-10-9
 * Time: 上午11:57
 * Description: keys
 */
import hash from './hash';
import convert from './convert';
let Buffer = require('buffer/').Buffer;

function getPrivateAndPublicKeyFromSecret(secret) {
  let sha256Hash = hash.getSha256Hash(secret, 'utf8');
  let keyPair = global.naclInstance.crypto_sign_seed_keypair(sha256Hash);

  return {
    privateKey: convert.bufferToHex(Buffer.from(keyPair.signSk)),
    publicKey: convert.bufferToHex(Buffer.from(keyPair.signPk))
  };
}

function getRawPrivateAndPublicKeyFromSecret(secret) {
  let sha256Hash = hash.getSha256Hash(secret, 'utf8');
  let keyPair = global.naclInstance.crypto_sign_seed_keypair(sha256Hash);

  return {
    privateKey: keyPair.signSk,
    publicKey: keyPair.signPk
  };
}

export default {
  getKeypair: getPrivateAndPublicKeyFromSecret,
  getPrivateAndPublicKeyFromSecret: getPrivateAndPublicKeyFromSecret,
  getRawPrivateAndPublicKeyFromSecret: getRawPrivateAndPublicKeyFromSecret
};
